"""
__author__ = 'heyanmin'
__time__ = '2021/4/18 2:47 下午'
"""
import time

from selenium.webdriver.common.by import By

from web_po_wechat.page.base_page import BasePage
from web_po_wechat.page.contact import ContactPage

# 添加成员

class AddMemberPage(BasePage):
    # 定义类变量，共用
    # 加 __ 是将变量变为私有变量，用例和页面之间解耦，变为私有变量，用例不可访问
    # 输入姓名
    __ele_name = (By.ID,"username")
    # 输入账号
    __ele_acctid = (By.ID,"memberAdd_acctid")
    # 输入手机号
    __ele_phone = (By.ID,"memberAdd_phone")
    # 保存按钮
    __ele_save = (By.CSS_SELECTOR,".js_btn_save")

    def add_member(self,name,acctid,phone):

        # 输入基本成员信息
        # * 作用解元祖，等同于 *self.ele_name=(By.ID, "username")
        # 方法中调用类变量，需要通过self.引用
        # self.driver.find_element(*self.__ele_name).send_keys(name)
        # 调用find方法
        self.find(self.__ele_name).send_keys(name)
        self.find(self.__ele_acctid).send_keys(acctid)
        self.find(self.__ele_phone).send_keys(phone)
        # 点击保存
        # self.driver.find_element(By.CSS_SELECTOR,".js_btn_save").click()
        self.find(self.__ele_save).click()
        # 页面的return 分为两个部分：1 返回其他页面的实例 2.用例断言
        return ContactPage(self.driver)

    def add_member_fail(self, name, acctid, phone):
        # 输入基本成员信息
        self.find(self.__ele_name).send_keys(name)
        self.find(self.__ele_acctid).send_keys(acctid)
        self.find(self.__ele_phone).send_keys(phone)
        self.find(self.__ele_save).click()
        element = self.driver.find_element(By.CSS_SELECTOR,".ww_inputWithTips_tips")
        error_list = []
        for ele in element:
            error_list.append(ele.text)
        return error_list

    def add_xxx(self):
        # 调用本身的实例
        # AddMemberPage()
        return self